import * as actionTypes from './constants';
import { fromJS } from 'immutable';
import { getRankListRequest } from '../../../api/request';


// 需要修改的state 有ranklist 和 loading
const changeRankList = (data) => {
    return ({
        type: actionTypes.CHANGE_RANK_LIST, 
        data: fromJS(data),
    })
};

const changeLoading = (data) => {
    return {
        type: actionTypes.CHANGE_LOADING,
        data,
    }
}; 

// 加载rankList
export const getRankList = () => {
    return dispatch => {
        getRankListRequest().then(data => {
            dispatch(changeRankList(data.list));
            dispatch(changeLoading(false));
        })
    };
};